import os
import sys


def getFileExten(fileName):
    return os.path.splitext(fileName)[-1][1:]


def BuildLua(path):
    lists = os.listdir(path)
    tarPath = path.replace("LuaScripts", "LuaBytes")
    if not os.path.exists(tarPath):
        print(tarPath)
        os.mkdir(tarPath)

    for fileName in lists:
        fullName = path + "/" + fileName
        if os.path.isdir(fullName):
            BuildLua(fullName)
        else:
            if getFileExten(fullName) == "lua":
                tarName = tarPath + "/" + fileName.replace(".lua", "") + ".bytes"
                cmdStr = "luac -o " + tarName + " " + fullName
                print(cmdStr)
                os.system(cmdStr)


if (__name__ == "__main__"):
    curpath = os.getcwd()
    curpath = curpath + "/../Assets/LuaScripts"
    BuildLua(curpath)
    os.system("pause")
    pass
